<!DOCTYPE html>
<html>
<head>
    <script src="../build/react.js"></script>
    <script src="../build/react-dom.js"></script>
    <script src="../build/browser.min.js"></script>
</head>
<body>
<div>Each Clock sets up its own timer and updates independently.</div>
<div id="example"></div>
<script type="text/babel">
    function FormattedDate(props) {
        return <h2>It is {props.date.toLocaleTimeString()}.</h2>;
    }

    class Clock extends React.Component {
        constructor(props) {
            super(props);
            this.state = {date: new Date()};
        }

        componentDidMount() {
            this.timerID = setInterval(
                () => this.tick(),
                1000
            );
        }

        componentWillUnmount() {
            clearInterval(this.timerID);
        }

        tick() {
            this.setState({
                date: new Date()
            });
        }

        render() {
            return (
                    <div>
                        <h1>Hello, world!</h1>
                        <FormattedDate date={this.state.date} />
                    </div>
            );
        }
    }

    function App() {
        return (
                <div>
                    <Clock />
                    <Clock />
                    <Clock />
                </div>
        );
    }

    ReactDOM.render(<App />, document.getElementById('example'));



</script>
</body>
</html>

